package com.huawei.controller;

import com.huawei.service.WebSocketServer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

@Controller
public class MyController {

    @GetMapping("/socket/{cid}")
    public ModelAndView socket(@PathVariable String cid){
        ModelAndView mav=new ModelAndView();
        mav.addObject("cid",cid);
        return mav;
    }

    @ResponseBody
    @GetMapping("/socket/push/{cid}")
    public String pushToWeb(@PathVariable String cid,String message){
        try {
            WebSocketServer.sendInfo(message,cid);
        }catch (IOException e){
            e.printStackTrace();
        }
        return "success";
    }
}
